{extend name="app/admin/view/base.html"/}
{block name="resources"}
<style>
	.ns-form {
		margin-top: 0;
	}
</style>
{/block}
{block name="main"}
<form class="layui-form ns-form">
	<div class="layui-form-item">
		<label class="layui-form-label"><span class="required">*</span>供应商名称：</label>
		<div class="layui-input-block">
			<input name="title" type="text" lay-verify="required"  value="{$info.title}" class="layui-input ns-len-long" autocomplete="off">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">LOGO：</label>
		<div class="layui-input-block">
			<div class="upload-img-block img-upload">
				
				<div class="upload-img-box {notempty name="$info['logo']"}hover{/notempty}">
					<div class="ns-upload-default" id="imgUpload">
						{if condition="$info.logo"}
						<div id="preview_imgUpload" class="preview_img">
							<img layer-src src="{:img($info.logo)}" class="img_prev"/>
						</div>
						{else/}
						<div class="upload">
							<img src="ADMIN_IMG/upload_img.png"/>
							<p>点击上传</p>
						</div>
						{/if}
					</div>
					<div class="operation">
						<div>
							<i title="图片预览" class="iconfont iconreview js-preview" style="margin-right: 20px;"></i>
							<i title="删除图片" class="layui-icon layui-icon-delete js-delete"></i>
						</div>
						<div class="replace_img js-replace">点击替换</div>
					</div>
					<input type="hidden" name="logo" value="{$info.logo}">
				</div>
			</div>
		</div>
		<div class="ns-word-aux">
			<p>建议图片尺寸：200px * 100px。</p>
			<p>图片格式：jpg、png、jpeg。</p>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label"><span class="required">*</span>主营行业：</label>
		<div class="layui-input-block ns-len-mid">
			<select class="ns-category" name="category_id" lay-verify="required">
				<option value="">选择主营行业</option>
				{volist name="$category_list" id="category"}
				<option value="{$category.category_id}" {if condition="$info.category_id eq $category.category_id" }selected{/if}>{$category.category_name}</option>
				{/volist}
			</select>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">到期时间：</label>
		<div class="layui-input-block">
			<input name="expire_time" type="text" id="laydate" value="{if condition='$info.expire_time'}{:date('Y-m-d', $info.expire_time)}{/if}" class="layui-input ns-len-mid" autocomplete="off">
		</div>
		<div class="ns-word-aux">
			<p>店铺关闭时间，与入驻时长相关联</p>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label"><span class="required">*</span>供应商关键字：</label>
		<div class="layui-input-block">
			<input name="keywords" type="text"  lay-verify="required" value="{$info.keywords}" class="layui-input ns-len-long" autocomplete="off">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label"><span class="required">*</span>供应商简介：</label>
		<div class="layui-input-block">
			<textarea class="layui-textarea ns-len-long" lay-verify="required" name="desc">{$info.desc}</textarea>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label"><span class="required">*</span>联系电话：</label>
		<div class="layui-input-block">
			<input type="text" name="supplier_phone" lay-verify="required" value="{$info.supplier_phone}" autocomplete="off" class="layui-input ns-len-long">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">供应商QQ：</label>
		<div class="layui-input-block">
			<input type="text" name="supplier_qq" value="{$info.supplier_qq}" autocomplete="off" class="layui-input ns-len-long">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">供应商微信：</label>
		<div class="layui-input-block">
			<input type="text" name="supplier_weixin" value="{$info.supplier_weixin}" autocomplete="off" class="layui-input ns-len-long">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">供应商邮箱：</label>
		<div class="layui-input-block">
			<input type="text" name="supplier_email" value="{$info.supplier_email}" lay-verify="isemail" autocomplete="off" class="layui-input ns-len-long">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">供货商状态：</label>
		<div class="layui-input-block">
			<input type="radio" name="status" lay-filter="status" value="1" title="正常" {if condition="$info.status == 1"} checked {/if}>
			<input type="radio" name="status" lay-filter="status" value="0" title="关闭" {if condition="$info.status != 1"} checked {/if}>
		</div>
		<div class="ns-word-aux">
			<p>关闭后，所有商品将被下架</p>
		</div>
	</div>

	<div class="ns-form-row">
		<button class="layui-btn ns-bg-color" lay-submit lay-filter="save">保存</button>
		<button type="reset" class="layui-btn layui-btn-primary" onclick="back()">返回</button>
	</div>
</form>
{/block}
{block name="script"}
<script>
	layui.use(['form', 'laydate'], function() {
		var form = layui.form,
			laydate = layui.laydate,
			repeat_flag = false;//防重复标识
		form.render();
		laydate.render({
			elem: '#laydate'
		});

		// 普通图片上传
		var logo_upload = new Upload({
			elem: '#imgUpload',
			url: ns.url("admin/upload/upload"),
		});

		form.on('submit(save)', function (data) {
			if (repeat_flag) return false;
			repeat_flag = true;
			
			//删除图片
			if(!data.field.logo) logo_upload.delete();
			
			data.field.category_name = $("select[name=category_id] option:selected").text();
			$.ajax({
				url: ns.url('supply://admin/supplier/edit', {site_id: '{$info.supplier_site_id}'}),
				data: data.field,
				dataType: 'json',
				type: 'post',
				success: function (res) {
					repeat_flag = false;
					if (res.code == 0) {
						layer.msg('编辑成功');
						location.href = ns.url('supply://admin/supplier/index');
					}else{
						layer.msg(res.message);
					}
				}
			});
			return false;
		});
	});

	function back(){
		location.href = ns.url("supply://admin/supplier/index")
	}
</script>
{/block}